package util;

import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

import juego.arcos.Arco;
import juego.arcos.Fuerte;
import juego.arcos.MedioFuerteVeloz;
import juego.arcos.Veloz;

import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;

public class TipoArcoType implements UserType {

	public Object assemble(Serializable arg0, Object arg1) throws HibernateException {
		return null;
	}

	public Object deepCopy(Object arg0) throws HibernateException {
		return arg0;
	}

	public Serializable disassemble(Object arg0) throws HibernateException {
		return null;
	}

	public boolean equals(Object arg0, Object arg1) throws HibernateException {
		return arg0.getClass() == arg1.getClass();
	}

	public int hashCode(Object arg0) throws HibernateException {
		return arg0.getClass().hashCode();
	}

	public boolean isMutable() {
		return false;
	}

	public Object nullSafeGet(ResultSet rs, String[] columns, Object arquero)	throws HibernateException, SQLException {
		String value = rs.getString(columns[0]);
		if(value == null)
			return null;
		
		if(value.equals("Veloz")) return new Veloz();
		if(value.equals("Fuerte")) return new Fuerte();
		if(value.equals("MedioFuerteVeloz")) return new MedioFuerteVeloz();
		
		return null;
	}

	public void nullSafeSet(PreparedStatement ps, Object arco, int pos)
			throws HibernateException, SQLException {
		ps.setString(pos, ((Arco)arco).getNombre());
		
		
		
	}

	public Object replace(Object arg0, Object arg1, Object arg2)
			throws HibernateException {
		return arg0;
	}

	public Class<Arco> returnedClass() {
		return Arco.class;
	}

	public int[] sqlTypes() {
		return new int[] { Types.VARCHAR };
	}

}
